﻿using CSharpFunctionalExtensions;
using FunasrSTT.Translate.ViewModels;
using HandyControl.Controls;
using HandyControl.Tools.Extension;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace FunasrSTT.Translate.Services;

/// <summary>
/// 对话框服务.
/// </summary>
public class DialogService
{
    private readonly LanguageService _languageService;

    public DialogService(LanguageService languageService)
    {
        _languageService = languageService;
    }

    private string L(string key) => _languageService.L(key);

    /// <summary>
    /// 显示提示对话框.
    /// </summary>
    /// <param name="title">提示对话框标题.</param>
    /// <param name="kind">提示对话框类型.</param>
    /// <param name="message">提示对话框信息.</param>
    /// <param name="confirmText">提示对话框消息文本.</param>
    public async Task AlertAsync(string title, ViewModels.DialogKind kind, string message, string confirmText)
    {
        await HandyControl.Controls.Dialog.Show<Views.AlertDialog>()
            .Initialize<ViewModels.AlertViewModel>(vm => vm.Initialize(title, kind, message, confirmText))
            .GetResultAsync<Maybe>();
    }

    /// <summary>
    /// 显示帮助提示对话框.
    /// </summary>
    /// <param name="title">帮助提示对话框标题.</param>
    /// <param name="message">帮助提示对话框信息.</param>
    public async Task HelpAsync(string title, string message)
    {
        await AlertAsync(title, ViewModels.DialogKind.Help, message, L("Text.OK"));
    }

    /// <summary>
    /// 显示信息提示对话框.
    /// </summary>
    /// <param name="title">信息提示对话框标题.</param>
    /// <param name="message">信息提示对话框信息.</param>
    public async Task InfoAsync(string title, string message)
    {
        await AlertAsync(title, ViewModels.DialogKind.Information, message, L("Text.OK"));
    }

    /// <summary>
    /// 显示成功提示对话框.
    /// </summary>
    /// <param name="title">成功提示对话框标题.</param>
    /// <param name="message">成功提示对话框信息.</param>
    public async Task SuccessAsync(string title, string message)
    {
        await AlertAsync(title, ViewModels.DialogKind.Success, message, L("Text.OK"));
    }

    /// <summary>
    /// 显示警告提示对话框.
    /// </summary>
    /// <param name="title">警告提示对话框标题.</param>
    /// <param name="message">警告提示对话框信息.</param>
    public async Task WarningAsync(string title, string message)
    {
        await AlertAsync(title, ViewModels.DialogKind.Warning, message, L("Text.OK"));
    }

    /// <summary>
    /// 显示错误提示对话框.
    /// </summary>
    /// <param name="title">错误提示对话框标题.</param>
    /// <param name="message">错误提示对话框信息.</param>
    public async Task ErrorAsync(string title, string message)
    {
        await AlertAsync(title, ViewModels.DialogKind.Error, message, L("Text.OK"));
    }

    /// <summary>
    /// 显示确认对话框.
    /// </summary>
    /// <param name="title">确认对话框标题.</param>
    /// <param name="message">确认对话框消息文本.</param>
    /// <param name="confirmText">确认对话框 `确认` 按钮文本.</param>
    /// <param name="cancelText">确认对话框 `取消` 按钮文本.</param>
    /// <returns>确认对话框交互结果.</returns>
    public async Task<Result> ConfirmAsync(string title, string message, string confirmText, string cancelText)
    {
        return await HandyControl.Controls.Dialog.Show<Views.ConfirmDialog>()
            .Initialize<ViewModels.ConfirmViewModel>(vm => vm.Initialize(title, message, confirmText, cancelText))
            .GetResultAsync<Result>();
    }

    /// <summary>
    /// 显示确认对话框.
    /// </summary>
    /// <param name="title">确认对话框标题.</param>
    /// <param name="message">确认对话框消息文本.</param>
    /// <returns>确认对话框交互结果.</returns>
    public async Task<Result> ConfirmAsync(string title, string message)
    {
        return await ConfirmAsync(title, message, L("Text.Confirm"), L("Text.Cancel"));
    }

}